package com.gugee.common.web.system.promise.validate;


import com.gugee.common.web.system.promise.repository.PermissionLimitRepository;
import com.gugee.common.web.system.user.repository.UserRepository;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RoleLimit extends Validate{

    @Autowired
    UserRepository userRepository;
    @Autowired
    PermissionLimitRepository permissionLimitRepository;

    @Override
    public Boolean validate(long roleId, Object... params) {
        val permissionLimitOptional = permissionLimitRepository.findByPermissionIdAndProductId(super.permissionId, roleId);

        if(permissionLimitOptional.isPresent()){
            if(permissionLimitOptional.get().getAllow().equals("1")){
                return true;
            }
            super.tips = permissionLimitOptional.get().getTips();
        }
        return false;
    }
}
